package com.moonlight.mina;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MinaHandler extends IoHandlerAdapter {
	private final static Logger logger = LoggerFactory.getLogger(MinaHandler.class);

	@Override
	public void sessionOpened(IoSession session) throws Exception {
		logger.info("tcp连接建立成功");
	}

	@Override
	public void sessionClosed(IoSession session) throws Exception {
		logger.info("tcp连接已断开");
	}
	
	@Override
    public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
        logger.info("tcp空闲状态中");
    }

	@Override
    public void messageReceived(IoSession session, Object message) throws Exception {
        logger.info("消息接受：{}" , message);
    }

    @Override
    public void messageSent(IoSession session, Object message) throws Exception {
        logger.info("消息发送：{}" , message);
    }
    
    @Override
    public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
        logger.error("网络传输异常：{}" , cause.toString());
    }
}
